package com.infocollect.project.api.ui;

import com.infocollect.project.api.req.SaveApiConfigReq;
import com.infocollect.project.api.req.SaveConfigShowCelNamesReq;
import com.infocollect.project.api.service.ITappApiConfigService;
import com.infocollect.project.api.vo.ApiConfigVO;
import com.infocollect.project.form.vo.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "apiconfig", tags = "Api接口配置信息")
@RestController
@RequestMapping("apiconfig")
public class TappApiconfigController {

    /**
     * 服务对象
     */
    @Resource
    private ITappApiConfigService tappApiconfigService;

    /**
     * Api保存方法
     *
     * @param apiParam
     * @return
     */
    @PostMapping("saveApiConfigInfo")
    @ResponseBody
    public R<String> saveApiConfigInfo(@RequestBody SaveApiConfigReq apiParam) throws Exception {
        return tappApiconfigService.saveApiConfigInfo(apiParam);

    }

    /**
     * 回滚指定版本
     *
     * @param callMethodCode
     * @param versions
     */
    @PostMapping("rollBack")
    @ResponseBody
    public R<String> rollBack(@RequestParam("callMethodCode") String callMethodCode, @RequestParam("versions") Integer versions) {
        tappApiconfigService.rollBack(callMethodCode, versions);
        return R.newOk();
    }

    /**
     * 根据回调方法编码获取接口配置信息
     *
     * @param callMethodCode
     * @return
     */
    @PostMapping("getApiConfigByCallMethodCode")
    @ResponseBody
    public R<ApiConfigVO> getApiConfigByCallMethodCode(@RequestParam("code") String callMethodCode) {
        return R.newOk(tappApiconfigService.getApiConfigByCallMethodCode(callMethodCode));
    }

    /**
     * 根据ID 获取Api配置方法
     *
     * @param fid
     * @return
     */
    @PostMapping("getApiConfigById")
    @ResponseBody
    public R<ApiConfigVO> getApiConfigById(@RequestParam("id") Long fid) {
        return R.newOk(tappApiconfigService.getApiConfigById(fid));
    }

    /**
     * 根据ID 进行删除Api接口
     *
     * @param fid
     * @return
     */
    @PostMapping("deleteMapping")
    @ResponseBody
    public R<String> deleteMapping(@RequestParam("id") Long fid) {
        return tappApiconfigService.deleteMapping(fid);
    }

    /**
     * 保存列表显示的列
     * @param param
     * @return
     */
    @PostMapping("saveConfigShowCelNames")
    public  R<String> saveConfigShowCelNames(@RequestBody SaveConfigShowCelNamesReq param){
        Boolean isSave=   tappApiconfigService.saveConfigShowCelNames(param);
        if(isSave){
            return R.newOk("保存成功！");
        }
        return R.newError("保存失败");
    }
}
